package cn.uin.types.utils;

import java.util.Random;

/**
 * @ClassName VerificationCodeUtils
 * @Description:类描述
 * @Author: Administrator
 * @CreateDate: 2025/10/29 15:17
 * @Version: 1.0
 */
public class VerificationCodeUtils {

	/**
	 * 生成6位数字验证码
	 * @return
	 */
	public static String generateNumericCode() {
		Random random = new Random();
		int code = 100000 + random.nextInt(900000); // 生成100000-999999范围的随机数
		return String.valueOf(code);
	}

	/**
	 * 生成包含数字和字母的混合验证码（可选）
	 * @return
	 */
	public static String generateAlphanumericCode() {
		String chars = "0123456789";
		Random random = new Random();
		char[] code = new char[6];
		for (int i = 0; i < 6; i++) {
			code[i] = chars.charAt(random.nextInt(chars.length()));
		}
		return new String(code);
	}

	/**
	 * 验证输入是否为有效6位验证码
	 * @param code
	 * @return
	 */
	public static boolean isValidCode(String code) {
		return code != null && code.matches("\\d{6}"); // 仅允许数字验证码校验
	}

}
